package com.pearl.jacksoncore.demo.core;

import com.fasterxml.jackson.core.*;
import com.pearl.jacksoncore.demo.pojo.User;

import java.io.File;
import java.io.IOException;

/**
 * @author TD
 * @version 1.0
 * @date 2024/3/18
 */
public class JsonParserDemo {
    public static void main(String[] args) throws IOException {
        // 1. 创建 JsonParser
        JsonFactory jsonFactory = JsonFactory.builder().build();
        File file = new File("E:\\TD\\pearl\\study-jackson-demo\\jackson-core-demo\\src\\main\\java\\com\\pearl\\jacksoncore\\demo\\file\\user.json");
        JsonParser jsonParser = jsonFactory.createParser(file);
/*        while (!jsonParser.isClosed()) {
            JsonToken jsonToken = jsonParser.nextToken();
            System.out.println("当前解析到的令牌类型：" + jsonToken);
        }*/

        // 2. 反序列化
        jsonParser.setCodec(new StudyObjectCodec());
        User user = jsonParser.readValueAs(User.class);
        System.out.println(user);
    }
}
